<template>
    <div>
     <HXR-GoogleMobileADBannerAd style="width:750rpx;height:50px;background-color: #555555;" adSize="kGADAdSizeBanner" adUnitID="ca-app-pub-3940256099942544/2934735716" @adLoaded="myload()" @adFail="myfail()"></HXR-GoogleMobileADBannerAd>
        <HXR-GoogleMobileADBannerAd style="width:750rpx;height:100px;background-color: #555555;" adSize="kGADAdSizeLargeBanner" adUnitID="ca-app-pub-3940256099942544/2934735716"></HXR-GoogleMobileADBannerAd>
        <HXR-GoogleMobileADBannerAd style="width:300px;height:250px;background-color: #555555;" adSize="kGADAdSizeMediumRectangle" adUnitID="ca-app-pub-3940256099942544/2934735716"></HXR-GoogleMobileADBannerAd>
        <HXR-GoogleMobileADBannerAd style="width:750rpx;height:50px;background-color: #555555;" adSize="kAutoHeightWithWidth" adUnitID="ca-app-pub-3940256099942544/2934735716"></HXR-GoogleMobileADBannerAd>
    
	 <!-- <button type="default" @click="showInterstitialAd()">插屏广告</button> -->
        <button type="default" @click="showRewardedAd()">激励广告</button>
        <button type="default" @click="showInterstitialRewardedAd()">插屏激励广告</button>
  
   <!-- <button type="default" @click="reback()">操作成功，点击返回</button> -->
   </div>
</template>
<script>
	// import AD from "../../js/ad2.js";
	
    var googleInterstitialAd = uni.requireNativePlugin('HXR-GoogleMobileADInterstitialAd');
    var googleRewardedAd = uni.requireNativePlugin('HXR-GoogleMobileADRewardedAd');
    var googleInterstitialRewardedAd = uni.requireNativePlugin('HXR-GoogleMobileADRewardedInterstitialAd');
    var testModule = uni.requireNativePlugin("Test")
	
    export default {
		onReady() {
		
		},
		methods: {
			handleMessage(evt) {
				console.log('接收到的消息：' + JSON.stringify(evt.detail.data[0].yaogg));
				if(JSON.stringify(evt.detail.data[0].yaogg)==1){
					console.log('start google Ad');
					this.showRewardedAd();
				}
			},
		    myload:function(e){
		        uni.showToast({
		            title:'加载完成',
		        }),
				this.showRewardedAd();
		    },
		    myfail:function(e){
		        uni.showToast({
		            title:'加载失败'
		        })
		    },
		    showRewardedAd:function(){
		        googleRewardedAd.showWithCallback(function(res){
		            console.log(JSON.stringify(res));
					// console.log(e.isEnded);
					// if (e.isEnded==true) {
						// 正常播放结束
						// console.log("onClose " + e.isEnded);
						uni.setStorageSync('ykgg', 1)
						uni.showToast({
							title:JSON.stringify(res).toString(),
							icon: 'none'
						});
						// var pages = getCurrentPages();
						// var prepage = pages[pages.length - 2]; //上一个页面
						// prepage.$vm.title = "222";
						// uni.navigateBack({
						// });
					// } else {
					// 	uni.setStorageSync('ykgg', 0)
					// 	// 播放中途退出
					// 	console.log("onClose " + e.isEnded);
					// 	uni.showToast({
					// 		title: '未观看完成',
					// 		icon: 'none'
					// 	});
					// 	// uni.navigateBack()
					// 	var pages = getCurrentPages();
					// 	var prepage = pages[pages.length - 2]; //上一个页面
					// 	prepage.$vm.title = "222";
					// 	uni.navigateBack({
					// 	});
					// }
		        });
		    },
			reback:function(options){
				var pages = getCurrentPages();
				var prepage = pages[pages.length - 2]; //上一个页面
				prepage.$vm.title = "222";
				uni.navigateBack({
				});
				// uni.navigateBack()
			},
		},
		onBackPress() {
			console.log("111111111111")
		},
        data() {
            return {
            }
        },
        onLoad() {
			
			let userInfo = uni.getStorageSync('userInfo');
            // googleInterstitialAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4411468910', (res) => {
            //     console.log(JSON.stringify(res));
            //     uni.showToast({
            //         title:res.msg
            //     })
            // });

            ////不传入验证参数
            // googleRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/1712485313', function(res){
            //  console.log(JSON.stringify(res));
            // });
			 googleRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/1712485313', function(res){
				 console.log(JSON.stringify(res));
			 }, {'userIdentifier':'your user identifier', 'customRewardString': 'your customRewardString'});
	
			this.showRewardedAd();
            ////不传入验证参数
            // googleInterstitialRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4806952744', function(res){
            //  console.log(JSON.stringify(res));
            // });
            // googleInterstitialRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4806952744', function(res){
            //     console.log(JSON.stringify(res));
            // }, {'userIdentifier':'your user identifier', 'customRewardString': 'your customRewardString'});
		},
		onReady() {
			var that = this;
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			this.headerPosition = e.scrollTop >= 0 ? "fixed" : "absolute";
			this.headerTop = e.scrollTop >= 0 ? null : 0;
			this.statusTop = e.scrollTop >= 0 ? null : -this.statusHeight + 'px';
		}
    }
</script>

<style>

</style>